<?php
include ("Clases/importarSQL.php");
include("Seguridad/seguridad_ad.php");
include("Clases/conectar_servidor.php");
$c_db=new conect_db();
$c_db->conectar();
$archivo_sql=$_FILES['fl_db']['name'];
$_fileName="db/".$archivo_sql;


if(!copy($_FILES['fl_db']['tmp_name'],$_fileName)){
	header ("location:subir_datos.php?r=F");								   	
}else{
	$sql1="DROP TABLE IF EXISTS alumnos";
	$sql2="DROP TABLE IF EXISTS asignaturas";
	$sql3="DROP TABLE IF EXISTS calificaciones";
	$sql4="DROP TABLE IF EXISTS carreras";
	$sql5="DROP TABLE IF EXISTS oferta_academica";
	$sql6="DROP TABLE IF EXISTS personal";
	
	if (mysql_query($sql1) and mysql_query($sql2) and mysql_query($sql3) and mysql_query($sql4) and mysql_query($sql5) and mysql_query($sql6)){
			
		$host =$c_db->dbhost;
		$dbUser = $c_db->dbusuario;
		$dbPassword = $c_db->dbpassword;
		
		$sqlFile = "$_fileName";
		$db_se=$c_db->db;
		
		$newImport = new sqlImport ($sqlFile, $host, $dbUser, $dbPassword, $db_se );
		$newImport -> import ();
		
		  if ($newImport-> error)exit(header ("location:subir_datos.php?r=F"));
		  else header ("location:subir_datos.php?r=T");
  
	}else{
		header ("location:subir_datos.php?r=F");
	}	
}
?> 